package com.leijie.thrift;

import com.leijie.thrift.Persion;
import com.leijie.thrift.PersionService;
import org.apache.thrift.TException;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFastFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

/**
 * @author LeiJie
 * @time 2020-4-30 14:28
 * @desc TODO
 */
public class ThriftClient {

    public static void main(String[] args) {
        TTransport tTransport = new TFastFramedTransport(new TSocket("localhost",8899));
        TProtocol tProtocol = new TCompactProtocol(tTransport);
        PersionService.Client client = new PersionService.Client(tProtocol);
        try {
            tTransport.open();
            Persion persion = client.getPersionByName("张三");
            System.out.println("getpersion:"+persion.getName() +">>>"+ persion.getAge() +">>>"+ persion.isMarried());
            Persion persion1 = new Persion();
            persion1.setName("测试");
            persion1.setAge(2000);
            persion1.setMarried(true);
            client.savePersion(persion1);
        } catch (TTransportException e) {
            e.printStackTrace();
        } catch (TException e) {
            e.printStackTrace();
        } finally {
            tTransport.close();
        }
    }

}
